/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License Version
 *  3 as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
 *  USA.
 */

#include <iostream>


#include <stdlib.h>
#include <Core/logger/logger.h>
#include "console.h"
#include <Core/task.h>

int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);
    Opl::Core::Logger::Initialize("console.log", "trace");
    Console con;
    con.Start();

//    if (!optra.Se(host, port)){
//        QTextStream err(stderr, QFile::WriteOnly);
//        err << QString("Can't connect to:%1 port:%2").arg(host).arg(port);
//        return EXIT_FAILURE;
//    }
   // Opl::Core::Task::sleep(500);

#if 0
    if (! *++argv) {
        interactive();
        return EXIT_SUCCESS;
    }

    while (const char *arg = *argv++) {
        QString fn = QString::fromLocal8Bit(arg);

        if (fn == QLatin1String("-i")) {
            interactive();
            break;
        }

        QString contents;
        int lineNumber = 1;

        if (fn == QLatin1String("-")) {
            QTextStream stream(stdin, QFile::ReadOnly);
            contents = stream.readAll();
        }

        else {
            QFile file(fn);

            if (file.open(QFile::ReadOnly)) {
                QTextStream stream(&file);
                contents = stream.readAll();
                file.close();

                // strip off #!/usr/bin/env qscript line
                if (contents.startsWith("#!")) {
                    contents.remove(0, contents.indexOf("\n"));
                    ++lineNumber;
                }
                if (!sendcommand(contents)){
                    return EXIT_FAILURE;
                }
            }
        }

        if (contents.isEmpty())
            continue;

    }
#endif
    return app.exec();
}
